#include<stdio.h>
#include<malloc.h>
#define MaxSize 50
typedef char ElemType;
char w;
typedef struct
{
    ElemType data[MaxSize];
    int front,rear;
}SqQueue;
void InitQueue(SqQueue*&q)
{
    q=(SqQueue*)malloc(sizeof(SqQueue));
    q->front=q->rear=0;
}
bool enQueue(SqQueue*&q,ElemType e)
{
    if((q=>rear+1)%MaxSize==q->front)
    return flase;
    q->rear=(q->rear+1)%MaxSize;
    q->data[q->rear]=e;
    return true;
}
bool QueueEmpty(SqQueue*q)
{
    return(q->front==q->rear);
}
bool deQueue(SqQueue*&q,ElemType&e)
{
    if(q->front==q->rear)
    return flase;
    q->front=(q->front+1)%MaxSize;
    e=q->data[q->front];
    return true;
}
void DestroyQueue(SqQueue*&q)
{
    free(q);
}
int main()
{
    SqQueue&q;
    printf("环形队列的各种基本运算的算法\n");
    printf("(1)初始化环形队列\n");
    InitQueue(q);
    printf("(2)依次进队元素a,b,c\n");
    if(!enQueue(q,"a"))
    printf("\t提示：队满，不能进队\n");
    if(!enQueue(q,"b"))
    printf("\t提示：队满，不能进队\n");
    if(!enQueue(q,"c"))
    printf("\t提示：队满，不能进队\n");
    printf("(5)依次进队元素d,e,f\n");
    if(!enQueue(q,"d"))
    printf("\t提示：队满，不能进队\n");
    if(!enQueue(q,"e"))
    printf("\t提示：队满，不能进队\n");
    if(!enQueue(q,"f"))
    printf("\t提示：队满，不能进队\n");
    printf("(6)输出出队序列：\n");
    while(!QueueEmpty(q))
    {
        deQueue(q,w);
        printf("%c",w);
    }
    printf("\n");
    printf("(7)释放队列\n");
    DestroyQueue(q);
    return 0;
}